﻿using System;
using System.Collections.Generic;
using MiniJSON;
using UILib;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x020008BD RID: 2237
	internal class AdditionRemindDocument : XDocComponent
	{
		// Token: 0x17002A65 RID: 10853
		// (get) Token: 0x0600872C RID: 34604 RVA: 0x00114518 File Offset: 0x00112718
		public override uint ID
		{
			get
			{
				return AdditionRemindDocument.uuID;
			}
		}

		// Token: 0x0600872D RID: 34605 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		protected override void OnReconnected(XReconnectedEventArgs arg)
		{
		}

		// Token: 0x0600872E RID: 34606 RVA: 0x0011452F File Offset: 0x0011272F
		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			this.is3G = (Application.internetReachability == (NetworkReachability)1);
		}

		// Token: 0x0600872F RID: 34607 RVA: 0x00114548 File Offset: 0x00112748
		public override void Update(float fDeltaT)
		{
			base.Update(fDeltaT);
			bool flag = Time.time - this.lasttime > 5f;
			if (flag)
			{
				this.Free3GTimer();
				this.lasttime = Time.time;
			}
		}

		// Token: 0x06008730 RID: 34608 RVA: 0x0011458C File Offset: 0x0011278C
		public void OnRecieveAdditionTip(string msg)
		{
			this.cacheString = msg;
			bool flag = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall;
			if (flag)
			{
				this.ShowAddtionUI();
			}
		}

		// Token: 0x06008731 RID: 34609 RVA: 0x001145C0 File Offset: 0x001127C0
		public void Free3GTimer()
		{
			bool flag = this.LOGINTIME <= 0;
			if (flag)
			{
				this.LOGINTIME = XSingleton<XGlobalConfig>.singleton.GetInt("Free3GTime");
			}
			bool flag2 = this.FREQUENCY <= 0;
			if (flag2)
			{
				this.FREQUENCY = XSingleton<XGlobalConfig>.singleton.GetInt("Free3GDay");
			}
			bool flag3 = Time.time > (float)this.LOGINTIME && (this.is3G || this.gm_is_3g) && !AdditionRemindDocument.is_3g_tip && (ulong)this.loginday >= (ulong)((long)this.FREQUENCY) && !XSingleton<XLoginDocument>.singleton.freeflow && !DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.IsVisible() && !XSingleton<XTutorialMgr>.singleton.InTutorial && DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.IsVisible();
			if (flag3)
			{
				this.UpdateFreeState();
				AdditionRemindDocument.is_3g_tip = true;
				string @string = XStringDefineProxy.GetString("REM_3G");
				XSingleton<UiUtility>.singleton.ShowModalDialog(@string, XStringDefineProxy.GetString("REM_BUY"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this.Show3GFreeUI));
			}
		}

		// Token: 0x06008732 RID: 34610 RVA: 0x001146C8 File Offset: 0x001128C8
		public void SetFreeflowTime(uint time)
		{
			this.loginday = ((uint)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds - time) / 3600U;
		}

		// Token: 0x06008733 RID: 34611 RVA: 0x00114708 File Offset: 0x00112908
		private void UpdateFreeState()
		{
			PtcC2G_UpdateFreeflowHintInfo ptcC2G_UpdateFreeflowHintInfo = new PtcC2G_UpdateFreeflowHintInfo();
			TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
			ptcC2G_UpdateFreeflowHintInfo.Data.hint_time = (uint)timeSpan.TotalSeconds;
			XSingleton<XClientNetwork>.singleton.Send(ptcC2G_UpdateFreeflowHintInfo);
		}

		// Token: 0x06008734 RID: 34612 RVA: 0x00114758 File Offset: 0x00112958
		private bool Show3GFreeUI(IXUIButton button)
		{
			this.Open3GWebPage();
			DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetVisible(false, true);
			return true;
		}

		// Token: 0x06008735 RID: 34613 RVA: 0x00114780 File Offset: 0x00112980
		public void Open3GWebPage()
		{
			int num = (XSingleton<XLoginDocument>.singleton.Channel == XAuthorizationChannel.XAuthorization_QQ) ? 2 : 1;
			string value = XSingleton<XGlobalConfig>.singleton.GetValue("SignalKey");
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary["url"] = string.Format(XSingleton<XGlobalConfig>.singleton.GetValue("SignalFreeUrl"), new object[]
			{
				XSingleton<XLoginDocument>.singleton.OpenID,
				num,
				XSingleton<XUpdater.XUpdater>.singleton.XPlatform.UserMd5(string.Concat(new object[]
				{
					XSingleton<XLoginDocument>.singleton.OpenID,
					num,
					XSingleton<UiUtility>.singleton.GetTimeStamp(),
					"1231_LongZhiGuApp",
					XSingleton<UiUtility>.singleton.Decrypt(value)
				})).ToLower(),
				XSingleton<UiUtility>.singleton.GetTimeStamp(),
				"1231_LongZhiGuApp",
				XSingleton<XLoginDocument>.singleton.TokenCache
			});
			dictionary["screendir"] = "SENSOR";
			bool isEditor = Application.isEditor;
			if (isEditor)
			{
				Application.OpenURL(dictionary["url"]);
			}
			else
			{
				XSingleton<XUpdater.XUpdater>.singleton.XPlatform.SendExtDara("open_url", Json.Serialize(dictionary));
			}
		}

		// Token: 0x06008736 RID: 34614 RVA: 0x001148C4 File Offset: 0x00112AC4
		public void ShowAddtionUI()
		{
			bool inTutorial = XSingleton<XTutorialMgr>.singleton.InTutorial;
			if (!inTutorial)
			{
				bool flag = !string.IsNullOrEmpty(this.cacheString);
				if (flag)
				{
					XSingleton<UiUtility>.singleton.ShowModalDialog(this.cacheString, XStringDefineProxy.GetString(XStringDefine.COMMON_OK));
				}
				this.cacheString = null;
			}
		}

		// Token: 0x06008737 RID: 34615 RVA: 0x00114914 File Offset: 0x00112B14
		public override void OnEnterSceneFinally()
		{
			base.OnEnterSceneFinally();
			bool flag = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall;
			if (flag)
			{
				this.ShowAddtionUI();
				bool flag2 = this.uploadtime < 1;
				if (flag2)
				{
					this.OnUploadUrl();
				}
			}
		}

		// Token: 0x06008738 RID: 34616 RVA: 0x0011495E File Offset: 0x00112B5E
		public override void OnDetachFromHost()
		{
			this.uploadtime = 0;
			base.OnDetachFromHost();
		}

		// Token: 0x06008739 RID: 34617 RVA: 0x00114970 File Offset: 0x00112B70
		public void OnUploadUrl()
		{
			bool flag = XSingleton<PDatabase>.singleton.playerInfo != null;
			if (flag)
			{
				this.uploadtime++;
				PtcC2G_PicUrlNtf ptcC2G_PicUrlNtf = new PtcC2G_PicUrlNtf();
				bool flag2 = XSingleton<XLoginDocument>.singleton.Channel == XAuthorizationChannel.XAuthorization_QQ;
				if (flag2)
				{
					ptcC2G_PicUrlNtf.Data.url = XSingleton<PDatabase>.singleton.playerInfo.data.pictureLarge;
				}
				else
				{
					ptcC2G_PicUrlNtf.Data.url = XSingleton<PDatabase>.singleton.playerInfo.data.pictureMiddle;
				}
				XSingleton<XClientNetwork>.singleton.Send(ptcC2G_PicUrlNtf);
			}
		}

		// Token: 0x04002A9D RID: 10909
		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("AdditionRemindDocument");

		// Token: 0x04002A9E RID: 10910
		private bool is3G = false;

		// Token: 0x04002A9F RID: 10911
		private static bool is_3g_tip = false;

		// Token: 0x04002AA0 RID: 10912
		private string cacheString = null;

		// Token: 0x04002AA1 RID: 10913
		private int uploadtime = 0;

		// Token: 0x04002AA2 RID: 10914
		public uint loginday = 10U;

		// Token: 0x04002AA3 RID: 10915
		public bool gm_is_3g = false;

		// Token: 0x04002AA4 RID: 10916
		public int FREQUENCY = 0;

		// Token: 0x04002AA5 RID: 10917
		public int LOGINTIME = 0;

		// Token: 0x04002AA6 RID: 10918
		private float lasttime = 10f;
	}
}
